package ibmetp.mis.serviceImpl;

import java.util.List;

import ibmetp.mis.common.Constants;
import ibmetp.mis.dao.UserDao;
import ibmetp.mis.service.PageService;
import ibmetp.mis.service.UserService;
import ibmetp.mis.vo.Page;
import ibmetp.mis.vo.User;
/**
 * UserService实现类
 * @author LAN DABIN
 * @created 2011-10-1
 *
 */
public class UserServiceImpl implements UserService, PageService {
    private UserDao ud=new UserDao();
    
	public User getUserById(Long id) {
			return ud.getUserById(id);
	}
     public Page getFreeUsers(int pageNo, int pageSize, Object object){
    	return ud.getFreeUsers(pageNo, pageSize, object);
     }
	public Page getPage(int pageNo, int pageSize, Object object) {
		
		Page page=ud.getUserPage(pageNo, pageSize, object);
		return page;
	}

	public String addUser(User user) {
		
		if(ud.getUserByNo(user.getUserNo())!=null)
		{
			return Constants.USER_EXISTS;
		}
		ud.addUser(user);
		return null;
	}

	public String updateUser(User user) {
		User u=ud.getUserByNo(user.getUserNo());
		
	    if(u!=null&&!u.getUserId().equals(user.getUserId()))
	    {   
	    	System.out.println(u.getUserId()+"::"+user.getUserId());
	    	return Constants.USER_EXISTS;
	    }
		ud.updateUser(user);
		return null;
	}

	public String deleteUserByIds(String userIds) {
		ud.deleteByIds(userIds);
		return null;
	}

	public String importUsers(List<User> users) {
		for(int i=0;i<users.size();i++){
			User user=users.get(i);
			System.out.println("userservice:"+user.getUserName());
			User u=ud.getUserByNo(user.getUserNo());
		   if(u==null)//若不存在该用户
			 ud.addUser(user);			
		   else{
			 user.setUserId(u.getUserId());
			 ud.updateUser(user);			 	 
	    	 }
		}
		return null;
	}

	public User getUserByNo(String userNo) {
		
		return ud.getUserByNo(userNo);
	}
	public String outOfDept(String userIds) {	
		String result=null;
		ud.outOfDept(userIds);	
		return result;
	}
	
	public User hasUser(String userNo, String pwd) {
		return ud.hasUser(userNo, pwd);
	}
	public String selectUserIntoDept(String userIds, Long deptId) {
		
		return ud.intoDept(userIds, deptId);
	}
	public Page getRoleUsers(Long roleId, int pageNo, int pageSize,
			Object object) {
		
		return ud.getRoleUsers(pageNo, pageSize, roleId, object);
	}

	

}
